<?php
	ob_start();
	session_start();
	include("../config.php");
?>
<!DOCTYPE HTML>
	<html lang="bg">
	<head>
		<meta charset="UTF-8">
		<title>Администраторски панел - АУТО ХИТ оод</title>
		<meta name="keywords" content="">
		<meta name="description" content="">
		<link rel="stylesheet" href="css/login.css">
	</head>
	<body>
<?php		
		if(isset($_POST['username']) && isset($_POST['password']))
		{
			$username = trim($_POST['username']);
			$password = trim($_POST['password']);

			if( ($username=="admin") && ($password=="123456") )
			{
				$_SESSION['admin_user_id']	= 1;
				$_SESSION['admin_username']	= $username;

				$_SESSION['start']	= time();
				// $_SESSION['expire']	= $_SESSION['start'] + (60 * 60);  // 1 hour

				header('Location: manufacturers.php');
			}
			else{
				$valid_errors = array();
					
				if(empty($username))
					$valid_errors[] = 'Моля въведете потребителско име!';
				elseif(empty($password))
					$valid_errors[] = 'Моля въведете парола!';
				else{
					if(empty($password))
						$valid_errors[] = 'Моля въведете парола!';

					if( ($username!="admin") || ($password!="123456") )
						$valid_errors[] = 'Грешно въведени (потребителско име / парола)!';
				}
			}
		}
?>
		<div id="page">
			<div id="main">
				<form name="fmain" method='POST'>
					<table id="tbl_login" border="0" width="100%" cellpadding="0" cellspacing="0">
						<?php
							if (!empty($valid_errors))
							{
						?>
						<tr>
							<td colspan="2">

								<div class="error_message">
									<p>Валидиране на входните данни:</p>
									<ul>
										<?php
											foreach ($valid_errors as $error) {
												echo "<li>$error</li>";
											}
										?>
									</ul>
								</div>
							</td>
						</tr>
						<?php } ?>
						<tr>
							<td height="25" colspan="2">
								<div id="topBoxLogin">
									<div id="leftBoxLogin">
										<h1>Вход в системата</h1>
									</div>
									<div id="rightImgLogin">
										<img src="images/stock_lock.png"  alt="" />
									</div>
								</div>
							</td>
						</tr>
						<tr>
							<td height="25" width="130">Потребителско име:&nbsp;<span style='color: #ff0000;'>*</span></td>
							<td align="right"><input type="text" name="username" class="inp_login" style="width: 210px;" maxlength="30" /></td>
						</tr>
						<tr>
							<td height="25">Парола:&nbsp;<span style='color: #ff0000;'>*</span></td>
							<td align="right"><input type="password" name="password" class="inp_login" style="width: 210px;" maxlength="40" /></td>
						</tr>
						<tr>
							<td height="55"></td>
							<td align="right">
								<input type="submit" name="btn_login" style="background: #dedede; color: #000000; border: 1px solid #949494; width: 60px; padding:5px;" value="Вход" />
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</body>
</html>